package com.cxl.autocode.create;

import java.io.File;
import java.util.List;

import javax.servlet.ServletContext;

import com.cxl.autocode.data.BeanInfo;
import com.cxl.autocode.data.FieldInfo;
import com.cxl.autocode.data.SmrFrame;
import com.cxl.autocode.data.SmrFrameInSamePackageImpl;
import com.cxl.autocode.data.TableInfo;
import com.cxl.autocode.util.ConfigurationHelper;
import com.cxl.price.bean.Ptype;
import com.summer.core.autocode.AutoCodeCreate;
import com.summer.core.autocode.AutoCodePath;
import com.summer.core.entity.Field;
import com.summer.core.entity.STable;




public class AutoSummerCode implements AutoCodeCreate {
	
	JavaGenerator javaGenerator=new JavaGeneratorImpl();
	
	JspGenerator jspGenerator=new JspGeneratorImpl();
	
	/**
	 * 
	 * @param path1 需要代码自动化生成dao,service,action对应的bean路径，不包含.java
	 * @param bean   实例模块参数bean
	 * @param
	 */
	public void createCode(STable bean,AutoCodePath path1)
	{
		
		SmrFrame path=(SmrFrame)path1;
		
		javaGenerator.genDaoInterface(path,bean);
		javaGenerator.genDaoImpl(path,bean);
		javaGenerator.genAction(path,bean);
		javaGenerator.genServiceImpl(path,bean);
		javaGenerator.genServiceInterface(path,bean);
	}
	
	
	public void createJsp(STable table,List<Field> fields)
	{
		jspGenerator.getListPage(fields, table);
		jspGenerator.getAddPage(fields, table);
		
	}
	
	//手工junit产生
	public void createJsp(Object obj)
	{
		BeanInfo info=new BeanInfo(obj);
		STable table=new TableInfo().getSTable(obj.getClass().getName());
		info.setPath(table.getPath());
		List<Field> fields=new FieldInfo().getList(table.getId());
		jspGenerator.getListPage(fields, table);
		jspGenerator.getAddPage(fields, table);
		
	}
	
	
	
	
	public static void main(String[] args) {
//		String beanPath="com.cxl.price.bean.Product";
//		new AutoSummerCode().createCode(beanPath,"产品","cxl","one");
		
		new AutoSummerCode().createJsp(new Ptype());
		
		
	}


	public void createCode(ServletContext context, STable table, AutoCodePath codepath) {
	
		SmrFrame path=(SmrFrame)codepath;
		
		javaGenerator.genDaoInterface(context,path,table);
		javaGenerator.genDaoImpl(context,path,table);
		javaGenerator.genAction(context,path,table);
		javaGenerator.genServiceImpl(context,path,table);
		javaGenerator.genServiceInterface(context,path,table);
		
	}


	public void createJsp(ServletContext context, STable table, List<Field> fields) {
		
		jspGenerator.getListPage(context,fields, table);
		jspGenerator.getAddPage(context,fields, table);
		
		
	}





	

	
	
}
